<template>
    <div>
        <div class="comInf">
            <div class="titel">{{$t('comreginf')}}</div>
            <el-row class="entType">
                <el-col :span="5"><div class="grid-content bg-purple">{{$t('tpofenter')}}</div></el-col>
                <el-col :span="19" class="right"><div class="grid-content bg-purple-light">{{merType}}</div></el-col>
            </el-row>
            <el-row class="merName">
                <el-col :span="5"><div class="grid-content bg-purple">{{$t('mertnam')}}</div></el-col>
                <el-col :span="19" class="right"><div class="grid-content bg-purple-light">{{companyName}}</div></el-col>
            </el-row>
            <el-row class="regNum">
                <el-col :span="5"><div class="grid-content bg-purple">{{$t('regnumber')}}</div></el-col>
                <el-col :span="19" class="right"><div class="grid-content bg-purple-light">{{registerNum}}</div></el-col>
            </el-row>
            <el-row class="regImg">
                <el-col :span="5"><div class="grid-content bg-purple">{{$t('regfilepic')}}</div></el-col>
                <el-col :span="19" class="right">
                    <div class="grid-content bg-purple-light">
                        <el-image :src="registerFileImgPath" :preview-src-list="imgUrl"></el-image>
                    </div>
                </el-col>
            </el-row>
            <el-row class="handle" v-if="operate === 'review'">
                <el-col :span="5"><div class="grid-content bg-purple">{{$t('opratn')}}</div></el-col>
                <el-col :span="19" class="right">
                    <div class="grid-content bg-purple-light">
                        <el-link type="primary" :underline="isOk" @click="auditPass('SUCCESS')">{{$t('passed')}}</el-link>
                        <el-link type="primary" :underline="isOk" @click="refuse('ERROR')">{{$t('refuse')}}</el-link>
                    </div>
                </el-col>
            </el-row>
            <el-row class="handle" v-if="operate === 'examine'">
                <el-col :span="5"><div class="grid-content bg-purple">{{$t('result')}}</div></el-col>
                <el-col :span="19" class="right">
                    <div class="grid-content bg-purple-light">
                        <div class="mhsb" v-if="pass === 'SUCCESS'">
                            <img src="../pic/suc.png">
                            <span class="mjsb">{{$t('passed')}}</span>
                        </div>
                        <div class="mhsb" v-if="pass === 'ERROR'">
                            <img src="../pic/err.png">
                            <span class="mjsb">{{$t('refuse')}}</span>
                        </div>
                        <div class="mhsb" v-if="ispend === 0 && pass !== 'SUCCESS' && pass !== 'ERROR'">
                            {{$t('notappplschk')}}
                        </div>
                    </div>
                </el-col>
            </el-row>
        </div>
        <div v-if="operate === 'examine' && ispend === 1">
            <div class="csc">{{$t('submtim')}}</div>
            <div class="remark">{{auditRemarks}}</div>
        </div>
        <el-dialog :title="$t('submtim')" :visible.sync="remDialogVisible" width="30%" center :modal-append-to-body="false">
            <el-input type="textarea" autosize v-model="auditForm.auditRemark"></el-input>
            <span slot="footer" class="dialog-footer">
                <el-button @click="remDialogVisible = false" v-preventReClick>{{$t('cnl')}}</el-button>
                <el-button type="primary" @click="commitAud" v-preventReClick>{{$t('cfm')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import {
    soncomaud,
    meraudit,
    getimgurl
} from '@/libs/reqlist.js'
export default {
    data () {
        return {
            ispend: 0,
            auditRemarks: '',
            operate: '',
            isOk: false,
            pass: '',
            remDialogVisible: false,
            perForm: {},
            merType: '',
            companyName: '',
            registerNum: '',
            companyType: '',
            registerFileImgPath: '',
            imgUrl: [],
            auditForm: {
                orderNo: '',
                auditStatus: '',
                auditRemark: '',
                parentAuditId: null,
                appType: null
            },
            becForm: {
                productCode: null,
                rateType: 'MER_PRO_RATE_TYPE',
                rateValue: null,
                additionRateValue: null,
                takeEffectTime: null,
                loseEfficacyTime: null,
                applyTime: null,
                remark: null
            }
        }
    },
    methods: {
        getOrderFrm () {
            meraudit(JSON.stringify({ parentOrderNo: this.auditForm.orderNo })).then(res => {
                this.perForm = res.data.data[1]
                this.auditForm.orderNo = res.data.data[1].orderNo
                this.auditForm.auditStatus = res.data.data[1].auditStatus
                this.merType = this.perForm.applyData.merType
                this.auditRemarks = this.perForm.auditRemark
                this.auditForm.appType = res.data.data[1].applyType
                if (this.merType === 'BIG_MER') this.merType = this.$t('entmercht')
                if (this.merType === 'SMALL_MER') this.merType = this.$t('smallbus')
                this.companyName = this.perForm.applyData.companyName
                this.registerNum = this.perForm.applyData.registerNum
                this.companyType = this.perForm.applyData.companyType
                if (this.perForm.auditStatus === 'SUCCESS') this.pass = 'SUCCESS'
                if (this.perForm.auditStatus === 'ERROR') this.pass = 'ERROR'
                getimgurl(JSON.stringify({ remoteFileName: this.perForm.applyData.registerFilePath })).then(res => {
                    if (res.data.code === '000000') {
                        this.registerFileImgPath = res.data.data.fileUrl
                        this.imgUrl.push(this.registerFileImgPath)
                    }
                })
            })
        },
        commitAud () {
            // if (this.$store.state.isRecheck) {
            //     let isweirm = this.$store.state.isRecheck.findIndex((value, index) => {
            //         return value.orderNo === this.auditForm.orderNo
            //     })
            //     if (isweirm === -1) {
            //         this.$store.commit('handleReview', this.auditForm)
            //     } else {
            //         this.$store.commit('handleReviewaaa', isweirm)
            //     }
            // }
            this.auditForm.auditRemark = this.auditForm.auditRemark.trim()
            soncomaud(this.auditForm).then(res => {
                if (res.data.code === '992125') {
                    this.$message.error(this.$t('audfailur'))
                }
                if (res.data.code === '000000') {
                    this.$message({
                        message: this.$t('audcomp'),
                        type: 'success'
                    })
                    if (this.auditForm.auditStatus === 'SUCCESS') {
                        this.pass = 'SUCCESS'
                        this.$parent.iscannext2('SUCCESS')
                    }
                    if (this.auditForm.auditStatus === 'ERROR') {
                        this.pass = 'ERROR'
                        this.$parent.iscannext2('ERROR')
                    }
                    this.remDialogVisible = false
                    window.localStorage.setItem('handlesp2', JSON.stringify(this.auditForm))
                    if (((JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp2')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp2')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp3')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp3')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp4')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp4')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp5')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp5')).auditStatus === 'ERROR'))) {
                        this.$parent.handledisab()
                    }
                }
            })
        },
        auditPass (txt) {
            this.remDialogVisible = true
            this.auditForm.auditStatus = txt
        },
        refuse (txt) {
            this.remDialogVisible = true
            this.auditForm.auditStatus = txt
        }
    },
    mounted () {
        this.operate = window.sessionStorage.getItem('operate')
        if (window.sessionStorage.getItem('operate')) this.operate = window.sessionStorage.getItem('operate')
        if (window.sessionStorage.getItem('orderSta') === this.$t('tobeaud')) {
            this.ispend = 0
        } else {
            this.ispend = 1
        }
        this.auditForm.orderNo = window.sessionStorage.getItem('handleOrder')
        if (this.operate === 'review') {
            this.kungfu = true
            if (window.localStorage.getItem('handlesp2')) {
                this.pass = JSON.parse(window.localStorage.getItem('handlesp2')).auditStatus
            }
            this.getOrderFrm()
        }
        if (this.operate === 'examine') {
            this.kungfu = false
            this.getOrderFrm()
        }
    }
}
</script>

<style lang="less" scoped>
@import './ownEnt.less';
</style>
